//
//  SelectAddressTableViewCell.m
//  customer
//
//  Created by Holothurian on 2018/11/3.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "SelectAddressTableViewCell.h"

@implementation SelectAddressTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _positoinImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"location_g"]];
        _positoinImgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_positoinImgView];
        [_positoinImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.contentView);
            make.left.mas_equalTo(weakSelf.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = Font(14);
        [self.contentView addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.left.equalTo(weakSelf.positoinImgView.mas_right).offset(10);
            make.size.mas_equalTo(CGSizeMake(F_DEVICE_W/2.0-30, 25));
        }];
        
        _phoneLabel = [[UILabel alloc]init];
        _phoneLabel.textColor = [UIColor blackColor];
        _phoneLabel.font = Font(14);
        _phoneLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_phoneLabel];
        [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.right.equalTo(weakSelf.contentView).offset(-10);
            make.size.mas_equalTo(CGSizeMake(F_DEVICE_W/2.0-30, 25));
        }];
        
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.textColor = [HSPublic colorWithHexString:@"#666666"];
        _addressLabel.font = Font(12);
        _addressLabel.numberOfLines = 0;
        [self.contentView addSubview:_addressLabel];
        [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.positoinImgView.mas_top).offset(5);
            make.left.equalTo(weakSelf.positoinImgView.mas_right).offset(10);
            make.right.equalTo(weakSelf.contentView.mas_right).offset(-10);
            make.height.mas_equalTo(25);
        }];
    }
    return self;
}


- (void)cellForLayout:(AddressModel *)model{
    self.nameLabel.text = model.address_name?:@"";
    self.phoneLabel.text = model.address_mobile?:@"";
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@",model.address_province,model.address_city,model.address_country,model.address_detailed];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


@implementation SelectAddressFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        UIView *backView = [[UIView alloc]init];
        backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:backView];
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf.contentView);
        }];
        _defaultAddressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_defaultAddressBtn setTitle:@"默认地址" forState:UIControlStateNormal];
        [_defaultAddressBtn setTitle:@"默认地址" forState:UIControlStateSelected];
        [_defaultAddressBtn setImage:[UIImage imageNamed:@"addressUnselected"] forState:UIControlStateNormal];
        [_defaultAddressBtn setImage:[UIImage imageNamed:@"locationSelectImg"] forState:UIControlStateSelected];
        [_defaultAddressBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        [_defaultAddressBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        _defaultAddressBtn.titleLabel.font = Font(12);
        [_defaultAddressBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
        [backView addSubview:_defaultAddressBtn];
        [_defaultAddressBtn addTarget:self action:@selector(defaultAddressEvent) forControlEvents:UIControlEventTouchUpInside];
        [_defaultAddressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(80, 20));
        }];
        

        _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_editBtn setTitle:@"编辑" forState:UIControlStateNormal];
        [_editBtn setTitle:@"编辑" forState:UIControlStateSelected];
        [_editBtn setImage:[UIImage imageNamed:@"addressManagerEdit"] forState:UIControlStateNormal];
        [_editBtn setImage:[UIImage imageNamed:@"addressManagerEdit"] forState:UIControlStateSelected];
        [_editBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        [_editBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        _editBtn.titleLabel.font = Font(12);
        [_editBtn addTarget:self action:@selector(editButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:_editBtn];
        [_editBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
        [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.right.equalTo(weakSelf.contentView).offset(-70);
            make.size.mas_equalTo(CGSizeMake(50, 20));
        }];
        
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteBtn setTitle:@"删除" forState:UIControlStateSelected];
        [_deleteBtn setImage:[UIImage imageNamed:@"addressManagerRubbish"] forState:UIControlStateNormal];
        [_deleteBtn setImage:[UIImage imageNamed:@"addressManagerRubbish"] forState:UIControlStateSelected];
        [_deleteBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        [_deleteBtn setTitleColor:[HSPublic colorWithHexString:@"#333333"] forState:UIControlStateSelected];
        _deleteBtn.titleLabel.font = Font(12);
        [_deleteBtn addTarget:self action:@selector(deleteButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:_deleteBtn];
        [_deleteBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
        [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.right.equalTo(weakSelf.contentView).offset(-10);
            make.size.mas_equalTo(CGSizeMake(50, 20));
        }];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)defaultAddressEvent{
    if ([self.delegate respondsToSelector:@selector(selectAddressSetDefaultAddress:)]) {
        [self.delegate selectAddressSetDefaultAddress:self.indexPath];
    }
}

- (void)editButtonEvent{
    if ([self.delegate respondsToSelector:@selector(selectAddressEditInformation:)]) {
        [self.delegate selectAddressEditInformation:self.indexPath];
    }
}

- (void)deleteButtonEvent{
    if ([self.delegate respondsToSelector:@selector(selectAddressDeleteInformation:)]) {
        [self.delegate selectAddressDeleteInformation:self.indexPath];
    }
}

@end
